﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EvidenceManagement.Logic.Security
{       
    public class SecurityPolicy
    {
        List<MonitoredModule> monitoredModules = new List<MonitoredModule>();

        /// <summary>
        /// Initializes a new instance of the <see cref="SecurityPolicy"/> class.
        /// </summary>
        public SecurityPolicy()
        {

        }

        /// <summary>
        /// Initializes a new instance of the <see cref="SecurityPolicy"/> class.
        /// </summary>
        /// <param name="policyName">Name of the policy.</param>
        public SecurityPolicy(string policyName)
        {
            PolicyName = policyName;
        }

        /// <summary>
        /// Gets or sets the name of the policy.
        /// </summary>
        /// <value>The name of the policy.</value>
        public string PolicyName
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the list of monitored modules.
        /// </summary>
        /// <value>The monitored modules.</value>
        public MonitoredModule[] MonitoredModules
        {
            get
            {
                return monitoredModules.ToArray();
            }
            set
            {
                monitoredModules = value.ToList<MonitoredModule>();
            }
        }

        protected internal void AddModule(MonitoredModule module)
        {
            if (!monitoredModules.Exists(a => a.Name == module.Name
                && a.ModuleType == module.ModuleType))
            {
                monitoredModules.Add(module);
            }
        }

        protected internal void AddModuleList(List<MonitoredModule> modules)
        {
            var filterdModules = modules.Where(m => !this.monitoredModules.Exists(e => e.Name == m.Name 
                && e.ModuleType == m.ModuleType));

            monitoredModules.AddRange(filterdModules);
        }

    }
}
